package chencb.stu.thrift.client;

import chencb.stu.thrift.interfaces.IUserInter;
import org.apache.thrift.TException;

import java.util.Date;

public class UserClient {

    public static void main(String[]args){
        try {
//            Date d1 = new Date();
//            IUserInter.Client userClient = (IUserInter.Client)BaseUtils.getClientWithnio(IUserInter.class.getName());
//            for(int i=0;i<20000;i++){
////                IUserInter.Client userClient = (IUserInter.Client)BaseUtils.getClientWithnio(IUserInter.class.getName());
//
//                String result = userClient.getById("yyyy");
//                System.out.println(result+"=========="+i);
//            }
//
//            Date d2 = new Date();
//
//            IUserInter.Client userClient1 = (IUserInter.Client)BaseUtils.getClient(IUserInter.class.getName());
//            for(int i=0;i<20000;i++){
////                IUserInter.Client userClient = (IUserInter.Client)BaseUtils.getClientWithnio(IUserInter.class.getName());
//
//                String result = userClient1.getById("yyyy");
//                System.out.println(result+"=========="+i);
//            }
//
//            Date d4 = new Date();
//            System.out.println(d2.getTime()-d1.getTime());
//
//            System.out.println(d4.getTime()-d2.getTime());


            new UserClient().test();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void test(){

        Date date = new Date();
        System.out.println(date);
        for(int i=0;i<10000;i++){
//            Thread thread = new Thread(new Server2Thread());
//            thread.start();

            Thread thread1 = new Thread(new ServerThread());
            thread1.start();
        }
    }

    class ServerThread extends Thread{

        @Override
        public void run() {
            IUserInter.Client userClient1 = null;
            try {
                userClient1 = (IUserInter.Client) BaseUtils.getClient(IUserInter.class.getName());
                String result = userClient1.getById("yyyy");
//                System.out.println(result+"==========");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    class Server2Thread extends Thread{

        @Override
        public void run() {
            IUserInter.Client userClient = (IUserInter.Client)BaseUtils.getClientWithnio(IUserInter.class.getName());
            String result = null;
            try {
                result = userClient.getById("yyyy");
            } catch (TException e) {
                e.printStackTrace();
            }
//            System.out.println(result+"==========");
        }
    }




}
